<template>
  <div />
</template>

<script>

export default {
  name: 'WebsiteStatistics',
  components: { },
  props: {
    str: {
      type: String,
      default() {
        return null
      }
    }
  },
  data() {
    return {
      filtrationPath: ['/page-design'],
      websiteStatisticsType: 'baidu_statistics',
      websiteStatisticsId: '036fc9766134275fa11f5757eb7717aa',
      isGoogleStatistics: false
    }
  },
  computed: {
  },
  watch: {
  },
  mounted() {
    this.getWebsiteStatistics()
  },
  methods: {
    getWebsiteStatistics() {
      if (this.filtrationPath.includes(this.$route.path)) {
        return
      }
      if (!this.websiteStatisticsType || !this.websiteStatisticsId) {
        return
      }
      // --百度统计
      if (this.websiteStatisticsType === 'baidu_statistics') {
        const _this = this
        var _hmt = _hmt || []
        window._hmt = _hmt; // 修改为window 全局变量
        (function() {
          const hm = document.createElement('script')
          hm.src = 'https://hm.baidu.com/hm.js?' + _this.websiteStatisticsId
          const s = document.getElementsByTagName('script')[0]
          s.parentNode.insertBefore(hm, s)
        })()

        window._hmt.push(['_trackPageview', this.str || this.$route.fullPath])
      }

      // // --谷歌统计
      // if (this.websiteStatisticsType === 'google_statistics' && this.isGoogleStatistics) {
      //   (function(i, s, o, g, r, a, m) {
      //     i.GoogleAnalyticsObject = r; i[r] = i[r] || function() {
      //       (i[r].q = i[r].q || []).push(arguments)
      //     }, i[r].l = 1 * new Date(); a = s.createElement(o),
      //     m = s.getElementsByTagName(o)[0]; a.async = 1; a.src = g; m.parentNode.insertBefore(a, m)
      //   })(window, document, 'script', 'https://www.google-analytics.com/analytics.js', 'ga')
      //
      //   ga('create', this.websiteStatisticsId, 'auto')
      //   ga('send', 'pageview') // 是否要统计着陆页面访问，取决于你的需求，这个不一定需要，会和`router`统计有重复
      //
      //   window.ga('set', 'page', this.str || this.$route.fullPath) // 你可能想根据请求参数添加其他参数，可以修改这里的 to.fullPath
      //   window.ga('send', 'pageview')
      // }
    }
  }
}
</script>

<style>

</style>
